home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / games / nhak_src.zip / STEAL.C < prev    next >
C/C++ Source or Header  |  1993-03-16  |  8KB  |  302 lines

  1. /*    SCCS Id: @(#)steal.c    3.0    88/07/06
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. #include "hack.h"
  6.  
  7. STATIC_DCL int NDECL(stealarm);
  8.  
  9. #ifdef OVLB
  10. static const char * FDECL(equipname, (struct obj *));
  11.  
  12. static const char *
  13. equipname(otmp)
  14.  
  15.     register struct obj *otmp;
  16. {
  17.  
  18.     return (
  19. #ifdef SHIRT
  20.         (otmp == uarmu) ? "shirt" :
  21. #endif
  22.         (otmp == uarmf) ? "boots" :
  23.         (otmp == uarms) ? "shield" :
  24.         (otmp == uarmg) ? "gloves" :
  25.         (otmp == uarmc) ? "cloak" :
  26.         (otmp == uarmh) ? "helmet" : "armor");
  27. }
  28.  
  29. long        /* actually returns something that fits in an int */
  30. somegold(){
  31. #ifdef LINT    /* long conv. ok */
  32.     return(0L);
  33. #else
  34.     return (long)( (u.ugold < 100) ? u.ugold :
  35.         (u.ugold > 10000) ? rnd(10000) : rnd((int) u.ugold) );
  36. #endif
  37. }
  38.  
  39. void
  40. stealgold(mtmp)
  41. register struct monst *mtmp;
  42. {
  43.     register struct gold *gold = g_at(u.ux, u.uy);
  44.     register long tmp;
  45.     if(gold && ( !u.ugold || gold->amount > u.ugold || !rn2(5))) {
  46.         mtmp->mgold += gold->amount;
  47.         freegold(gold);
  48.         if(Invisible) newsym(u.ux, u.uy);
  49.         pline("%s quickly snatches some gold from between your %s!",
  50.             Blind ? "It" : Monnam(mtmp), makeplural(body_part(FOOT)));
  51.         if(!u.ugold || !rn2(5)) {
  52.             rloc(mtmp);
  53.             mtmp->mflee = 1;
  54.         }
  55.     } else if(u.ugold) {
  56.         u.ugold -= (tmp = somegold());
  57.         Your("purse feels lighter.");
  58.         mtmp->mgold += tmp;
  59.         rloc(mtmp);
  60.         mtmp->mflee = 1;
  61.         flags.botl = 1;
  62.     }
  63. }
  64.  
  65. /* steal armor after he finishes taking it off */
  66. unsigned int stealoid;        /* object to be stolen */
  67. unsigned int stealmid;        /* monster doing the stealing */
  68.  
  69. STATIC_OVL int
  70. stealarm(){
  71.     register struct monst *mtmp;
  72.     register struct obj *otmp;
  73.  
  74.     for(otmp = invent; otmp; otmp = otmp->nobj)
  75.       if(otmp->o_id == stealoid) {
  76.         for(mtmp = fmon; mtmp; mtmp = mtmp->nmon)
  77.           if(mtmp->m_id == stealmid) {
  78.           if(otmp->unpaid) subfrombill(otmp);
  79.           freeinv(otmp);
  80.           pline("%s steals %s!", Blind ? "It" : 
  81.                     Monnam(mtmp), doname(otmp));
  82.           mpickobj(mtmp,otmp);
  83.           mtmp->mflee = 1;
  84.           rloc(mtmp);
  85.         break;
  86.           }
  87.         break;
  88.       }
  89.     return stealoid = 0;
  90. }
  91.  
  92. /* Returns 1 when something was stolen (or at least, when N should flee now)
  93.  * Returns -1 if the monster died in the attempt
  94.  * Avoid stealing the object stealoid
  95.  */
  96. int
  97. steal(mtmp)
  98. struct monst *mtmp;
  99. {
  100.     register struct obj *otmp;
  101.     register int tmp;
  102.     register int named = 0;
  103.  
  104.     /* the following is true if successful on first of two attacks. */
  105.     if(!monnear(mtmp, u.ux, u.uy)) return(0);
  106.  
  107.     if(!invent){
  108.         /* Not even a thousand men in armor can strip a naked man. */
  109.         if(Blind)
  110.           pline("Somebody tries to rob you, but finds nothing to steal.");
  111.         else
  112.           pline("%s tries to rob you, but she finds nothing to steal!",
  113.         Monnam(mtmp));
  114.         return(1);    /* let her flee */
  115.     }
  116.  
  117.     if(Adornment & LEFT_RING) {
  118.         otmp = uleft;
  119.         goto gotobj;
  120.     } else if(Adornment & RIGHT_RING) {
  121.         otmp = uright;
  122.         goto gotobj;
  123.     }
  124.  
  125.     tmp = 0;
  126.     for(otmp = invent; otmp; otmp = otmp->nobj) if(!uarm || otmp != uarmc)
  127.         tmp += ((otmp->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL)) ? 5 : 1);
  128.     tmp = rn2(tmp);
  129.     for(otmp = invent; otmp; otmp = otmp->nobj) if(!uarm || otmp != uarmc)
  130.           if((tmp -= ((otmp->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL)) ? 5 : 1))
  131.             < 0) break;
  132.     if(!otmp) {
  133.         impossible("Steal fails!");
  134.         return(0);
  135.     }
  136.     /* can't steal gloves while wielding - so steal the wielded item. */
  137.     if (otmp == uarmg && uwep)
  138.         otmp = uwep;
  139.     /* can't steal armor while wearing cloak - so steal the cloak. */
  140.     else if(otmp == uarm && uarmc) otmp = uarmc;
  141. #ifdef SHIRT
  142.     else if(otmp == uarmu && uarmc) otmp = uarmc;
  143.     else if(otmp == uarmu && uarm) otmp = uarm;
  144. #endif
  145. gotobj:
  146.     if(otmp->o_id == stealoid) return(0);
  147.  
  148. #ifdef WALKIES
  149.     if(otmp->otyp == LEASH && otmp->leashmon) o_unleash(otmp);
  150. #endif
  151.  
  152.     if((otmp->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL))){
  153.         switch(otmp->olet) {
  154.         case TOOL_SYM:
  155.             Blindf_off(otmp);
  156.             break;
  157.         case AMULET_SYM:
  158.             Amulet_off();
  159.             break;
  160.         case RING_SYM:
  161.             Ring_gone(otmp);
  162.             break;
  163.         case ARMOR_SYM:
  164.             /* Stop putting on armor which has been stolen. */
  165.             if (donning(otmp)) {
  166.               cancel_don();
  167.               if (otmp == uarm)  (void) Armor_off();
  168.               /* else if (otmp == uarmc) (void) Cloak_off(); */
  169.               else if (otmp == uarmf) (void) Boots_off();
  170.               else if (otmp == uarmg) (void) Gloves_off();
  171.               else if (otmp == uarmh) (void) Helmet_off();
  172.               /* else if (otmp == uarms) (void) Shield_off(); */
  173.               else setworn((struct obj *)0, otmp->owornmask & W_ARMOR);
  174.               break;
  175.             }
  176.             { int curssv = otmp->cursed;
  177.             otmp->cursed = 0;
  178.             stop_occupation();
  179.             if(flags.female)
  180.                 pline("%s charms you.  You gladly %s your %s.",
  181.                   Blind ? "She" : Monnam(mtmp),
  182.                   curssv ? "let her take" : "hand over",
  183.                   equipname(otmp));
  184.             else
  185.                 pline("%s seduces you and %s off your %s.",
  186.                   Blind ? "It" : Amonnam(mtmp, "beautiful"),
  187.                   curssv ? "helps you to take" : "you start taking",
  188.                   equipname(otmp));
  189.             named++;
  190.             /* the following is to set multi for later on */
  191.             (void) nomul(-objects[otmp->otyp].oc_delay);
  192.  
  193.             if (otmp == uarm)  (void) Armor_off();
  194.             else if (otmp == uarmc) (void) Cloak_off();
  195.             else if (otmp == uarmf) (void) Boots_off();
  196.             else if (otmp == uarmg) (void) Gloves_off();
  197.             else if (otmp == uarmh) (void) Helmet_off();
  198.             else if (otmp == uarms) (void) Shield_off();
  199.             else setworn((struct obj *)0, otmp->owornmask & W_ARMOR);
  200.             otmp->cursed = curssv;
  201.             if(multi < 0){
  202.                 /*
  203.                 multi = 0;
  204.                 nomovemsg = 0;
  205.                 afternmv = 0;
  206.                 */
  207.                 stealoid = otmp->o_id;
  208.                 stealmid = mtmp->m_id;
  209.                 afternmv = stealarm;
  210.                 return(0);
  211.             }
  212.             break;
  213.             }
  214.         default:
  215.             impossible("Tried to steal a strange worn thing.");
  216.         }
  217.     }
  218.     else if(otmp == uwep) uwepgone();
  219.  
  220.     if(otmp == uball) unpunish();
  221.  
  222.     freeinv(otmp);
  223.     pline("%s stole %s.", named ? "She" : (Blind ? "It" : Monnam(mtmp)), doname(otmp));
  224.     mpickobj(mtmp,otmp);
  225.     if (otmp->otyp == CORPSE && otmp->corpsenm == PM_COCKATRICE
  226.         && !resists_ston(mtmp->data)) {
  227.         pline("%s turns to stone.", Blind ? "It" : Monnam(mtmp));
  228.         stoned = TRUE;
  229.         xkilled(mtmp, 0);
  230.         return -1;
  231.     }
  232.     return((multi < 0) ? 0 : 1);
  233. }
  234.  
  235. #endif /* OVLB */
  236. #ifdef OVL1
  237.  
  238. void
  239. mpickobj(mtmp,otmp)
  240. register struct monst *mtmp;
  241. register struct obj *otmp;
  242. {
  243.     otmp->nobj = mtmp->minvent;
  244.     mtmp->minvent = otmp;
  245. }
  246.  
  247. #endif /* OVL1 */
  248. #ifdef OVLB
  249.  
  250. void
  251. stealamulet(mtmp)
  252. register struct monst *mtmp;
  253. {
  254.     register struct obj *otmp;
  255.  
  256.     for(otmp = invent; otmp; otmp = otmp->nobj) {
  257.         if(otmp->otyp == AMULET_OF_YENDOR) {
  258.         /* might be an imitation one */
  259.         setnotworn(otmp);
  260.         freeinv(otmp);
  261.         mpickobj(mtmp,otmp);
  262.         pline("%s stole %s!", Blind ? "It":Monnam(mtmp), doname(otmp));
  263.         rloc(mtmp);
  264.         return;
  265.         }
  266.     }
  267. }
  268.  
  269. #endif /* OVLB */
  270. #ifdef OVL0
  271.  
  272. /* release the objects the killed animal has stolen */
  273. void
  274. relobj(mtmp,show)
  275. register struct monst *mtmp;
  276. register int show;
  277. {
  278.     register struct obj *otmp, *otmp2;
  279.  
  280.     for(otmp = mtmp->minvent; otmp; otmp = otmp2){
  281.         otmp2 = otmp->nobj;
  282.         if (flooreffects(otmp,mtmp->mx,mtmp->my)) continue;
  283.         place_object(otmp, mtmp->mx, mtmp->my);
  284.         otmp->nobj = fobj;
  285.         fobj = otmp;
  286.         stackobj(fobj);
  287.         if(show & cansee(mtmp->mx,mtmp->my))
  288.             atl(otmp->ox,otmp->oy,Hallucination?rndobjsym() : otmp->olet);
  289.     }
  290.     mtmp->minvent = (struct obj *) 0;
  291.     if(mtmp->mgold || mtmp->data->mlet == S_LEPRECHAUN) {
  292.         register long tmp;
  293.  
  294.         tmp = (mtmp->mgold > 10000) ? 10000 : mtmp->mgold;
  295.         mkgold((long)(tmp + d(dlevel,30)), mtmp->mx, mtmp->my);
  296.         if(show & cansee(mtmp->mx,mtmp->my))
  297.             atl(mtmp->mx,mtmp->my, Hallucination ? rndobjsym() : GOLD_SYM);
  298.     }
  299. }
  300.  
  301. #endif /* OVL0 */
  302.